<?php
namespace Badmins\Controller;
use Think\Controller;
class AdminController extends Controller {
    public function index(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$name = I('name');
    	if(!empty($name)){
    		$where['a.name'] = array('like',"%{$name}%");
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = M('admin');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$join = "left join __ROLE__ as r on r.id = a.role_id";
    	$list = lists('admin as a',$join,$where,"a.*,r.name as rolename","a.id desc",$firstrow,$listrow,2);
    	if(!empty($list)){
    		foreach ($list as $i=>$va){
    			$list[$i]['login_time'] = M('login_log')->where("uid = '{$va['id']}' and type='0'")->getField('login_time');
    		}
    	}
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 角色管理
     */
    public function role(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$count = M('role')->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('role','',1,"*","id desc",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 管理员日志
     */
    public function log(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where['ol.admin_id'] = session('shopping_admin_id')?session('shopping_admin_id'):'1';
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$count = M('operation_log')->count();
    	$firstrow = ($p-1)*$listrow;
    	$join = "left join __ADMIN__ as a on ol.admin_id = a.id";
    	$list = lists('operation_log as ol',$join,$where,"ol.*,a.username","ol.id desc",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
}


